<!--Generate by Kevin's CodeBuilder -->
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
		<meta charset="UTF-8">
		<title>bui-ssm快速开发框架</title>
		<head th:include="source::header"></head>
		<style>
		
		</style>
</head>
<body>
	
	<div id="apiList" class="boxStyle" style="padding: 20px 30px;">
		<h2>模块列表:<select id="model_list"></select></h2>
	</div>
	<script type="text/javascript" th:inline="javascript">	
	
	function invoke(t){
		  var tr = $(t).parent().parent();
		  var td = tr.children().first();
		  var url = td.text();
		  var params = td.next().text();
		  var html = "<div>接口: "+url+"</div>";
		  html = html + "<div><p>参数：</p><p><textarea id='_p_input' style='margin: 0px; width: 781px; height: 366px;'></textarea></p></div>";
		  html = html + "<div style='text-align:center;'><button id='_invoke_btn'>调用</button></div>";
		  html = html + "<div>返回值: <p id='_res' style='word-break:break-all;'></p></div>"
		  var win = $B.window({
			  title:'接口调测',
			  width: 800,
			  height: 600,
			  content:html
		  });
		  var $res = win.jqObj.find("#_res");
		  var txt = win.jqObj.find("#_p_input").text(params);
		  win.jqObj.find("#_invoke_btn").click(function(){
			  try{
				  var prsObj = eval("("+txt.val()+")");
				  console.log(prsObj);
				  $B.request({
					  url:url,
					  data : prsObj,
					  ok:function(msg,res){
						  //$res.html(JSON.stringify(res));
					  },
					  final:function(res){
						  $res.html(JSON.stringify(res));
					  }
				  });
			  }catch(x){
				  $B.error("参数转换失败，请确认参数json格式的正确性！");
			  }			  
		  });
	}
	
    $(function(){ 
    	 var modelList = [];
    	 var apis = [(${apilist})];
    	 var controllers = [(${controllers})];
    	 var $apid = $("#apiList");
    	 var modelOpt = $("#model_list").on("change",function(){
    		 var v = $(this).val();
    		 if(v === "all"){
    			 window.location.href = ctxPath + "api/list";
    		 }else{
    			 window.location.href = ctxPath + "api/list?c="+v;
    		 }    		
    	 });
    	 
    	 for(var j = 0 ,jlen = controllers.length ;j < jlen ; j++){
    		 modelOpt.append("<option>"+controllers[j]+"</option>");
    	 }
    	 modelOpt.append("<option>all</option>");
    	 for(var i = 0 ,len = apis.length ;i < len ; ++i){
        	  var one = apis[i];
        	  $("<h6>模块："+one.controller+"</h6>").appendTo($apid );
        	  var actions = one.actions;
        	  
        	  var tab = $("<table style='width:100%;border:1px solid #c6c6c6;' class='form_table'/>").appendTo($apid );
        	  $("<tr style='background:#7CA5F5;'><td style='color:#fff;font-weight:bold;'>地址</td><td style='color:#fff;font-weight:bold;'>参数</td><td style='color:#fff;font-weight:bold;'>描述</td><td style='color:#fff;font-weight:bold;width:60px;'></td></tr>").appendTo(tab);
        	  for(var j = 0 ,jlen = actions.length ; j < jlen ; ++j){
            	   var a = actions[j];
            	   $("<tr style=''><td style='width:400px;border-bottom:1px dashed #E5E5E5;word-break:break-all;'>"+a.url+"</td><td style='text-align:left;border-bottom:1px dashed #E5E5E5;word-break:break-all;'>"+a.params+"</td><td style='border-bottom:1px dashed #E5E5E5;word-break:break-all;'>"+a.descript+"</td><td style='border-bottom:1px dashed #E5E5E5;width:60px;text-align:right;word-break:break-all;'><a style='cursor:pointer;' onclick='invoke(this)'>调用</a></td></tr>").appendTo(tab);
            }        	  
        }
    	 
	  });
	  
</script>
</body>
</html>